﻿using Microsoft.AspNetCore.SignalR;
using OpenAI.Infrastructure.Services;

namespace OpenAI.WebAPI.Hubs
{
    public class ChatMessageHub:Hub
    {
        private readonly ChatMessageService chatMessageService;

        public ChatMessageHub(ChatMessageService chatMessageService)
        {
            this.chatMessageService = chatMessageService;
        }

        public async Task SendMessage(int cid, string content, Guid appUserId, bool isBot)
        {
            var res = await chatMessageService.SendChatMessageAsync(cid, content, appUserId, isBot);
            if (res.Succeeded)
            {
                await Clients.All.SendAsync("ReceiveMessage");
            }
        }
    }
}
